<?php

namespace app\common\service;


class HostAddress extends Base
{
    /**
     * @name 列表
     * @param $params
     * @param $limit
     * @return array
     * @author wx
     * @date 2019/10/23 14:24
     */
    function list($params, $limit)
    {
        $db = db('host_address');

        if(isset($params['name']) && !empty($params['name'])){
            $db->where('name','like','%'.$params['name'].'%');
        }
        if(isset($params['address']) && !empty($params['address'])){
            $db->where('address','like','%'.$params['address'].'%');
        }
        if (isset($params['provider']) && !empty($params['provider'])) {
            $db->where('provider', $params['provider']);
        }
        if(isset($params['type']) && !empty($params['type'])){
            $db->where('type', $params['type']);
        }

        $data = $db->field('ctime',true)
            ->order('id desc')
            ->paginate($limit)->toArray();

        return $data;
    }

    /**
     * 资产添加
     */
    function add($addData)
    {
        return db('host_address')->insert($addData);
    }

    function modify($condition, $updateData)
    {
        return db('host_address')->where($condition)->update($updateData);
    }

    function del($condition)
    {
        return db('host_address')->where($condition)->delete();
    }

    /**
     * @name: 物理地址展示
     * @Param: addressId_a  id 数组
     * @Description: 
     * @Author: foo
     * @Date: 2019-03-27 10:08:32
     */
    function showAddress($addressId_a = [], $field = '', $index = '') 
    {
        $server = db('HostAddress');

        empty($addressId_a) ? : $server->whereIn('id', $addressId_a);
                
        empty($field) ? : $server->field($field);

        $addressData = empty($index) ? $server->select() : $server->column($field, $index);

        return $addressData;
    }
}